Skip to content


tag  jupyter  tips  ai  deep learning  beginner  regression  reinforcement learning  q learning  gym  gymnasium  ardupilot  None  ros2  dds  micro ros  xrce  sitl  plugin  gazebo  garden  SITL  debug  rangefinder  pymavlink  mavros  distance sensor  system_time  timesync  cmake  gtest  ctest  101  cpp  c++  format  fmt  multithreading  spdlog  cyclonedds  eprosima  fastdds  aptly  apt  repository  repo  local  mirror  encryption  pgp  docker  arm  container  state  networking  network  nvidia  python  app  devcontainer  gui  tutorial  volume  mount  compose  multi-stage  stage  docker compose  git  bundle  submodules  github  hooks  pre-commit  lxd  lxc  x11  profile  vscode  marpit  presentation  marp  markdown  mermaid  mkdocs  video  ffmpeg  gstreamer  cheat-sheet  sdp  v4l2loopback  gi  kml  geo  gis  spatial  gdal  ogr  raster  vector  snippets  cheat Sheet  asyncio  future  click  cli  cupy  numpy  gpu  dev container  deb  debian  package  setup  stdeb  project  hydra  yaml  configuration  matplotlib  3d  subplot  template  black  isort  templates  cookiecutter  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  from a-z  fixture  scope  logging  pytest.ini  mock  parameterize  enum  flag  iterator  generator  yml  logging config  tuple  namedtuple  typing  annotation  generic  literal  protocol  self  typed dict  typevar  pyzmq  zmq  msgpack  slam  cartographer  action  namespace  remap  control2  ros2_control  effort  velocity  gdb  qos  plugins  msg  node  zero-copy  shm  algorithm  calibration  diff  pid  dev  colcon  colcon_cd  settings  behavior  py_trees  bt  behavior_trees  blackboard  plot  visualization  debugging  diagnostic  DiagnosticTask  diagnostics  tutorials  gst  math  apm  rat_runtime_monitor  bag  rosbag  rosbags  tools  ros  web  rosbridge  vue  binding  discovery  gazebo-classic  launch  spawn  model  cook  camera  sensors  gps  imu  ray  gazebo_ros_ray_sensor  lidar  ultrsonic  range  ultrasonic  gazebo classic  wrench  odom  gz  sdf  world  vscode tips  gazebogz-sim-joint-position-controller-system  bridge  ign  ignition  xacro  diff_drive  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  nav  test  rclpy  goal abort  cancel goal  action client  action server  custom messages  executor  MultiThreadedExecutor  SingleThreadedExecutor  param  dynamic-reconfigure  service  client  setup.py  package.xml  parameter  parameters  custom  msgs  executers  pub  sub  rqt  rviz  rviz2  pose  marker  tf2  local_setup  rosdep  package manager  project settings  vcstool  urdf  robot_state_publisher  urdf_to_graphiz  joint  link  zenoh  tags  hands on  webinar  cross-compiler  nano  jetson  arduino  i2c  rpi  simulation  config  material  workshope  texture  joints  tmuxp  loop device  rootfs  embedded  zah  linux  rm  ubuntu  sudo  sudoers  nopasswd  visudo  udev  key  gpg  sign  commands  update-alternative  dpkg  ip  ss  netstat  snap  deploy  ssh  systemd  socat  serial  udp  tc  mtu  select  robotics  path planning  trajectory  speed  point cloud  pcl  kalman_filter  kalman  filter  control  code  extensions  remote  json  schema  yocto  poky  qemu  projects  courses to follow  matrix  graphics  rotation  2d  drone  quad  uav  design  vrx  buoyancy 

Docker and Python GUI application


Docker and Python GUI application#

Package and Deploy Python TKInter GUI application using Docker

Project#

.
├── .devcontainer
│   └── Dockerfile
├── py_gui_app
│   ├── app2.py
│   └── app.py
└── README.md

Dockerfile#

Using multistage Docker file - Base - Dev (TODO) - Deploy

FROM python:3.8.12-slim as app_base

RUN apt-get update -y

# Install Tkinter
RUN apt-get install tk -y

# Deploy
FROM app_base as app

# Copy app.py script to docker root
ADD /py_gui_app/app.py .
# cmd use as arguments to entrypoint
CMD ["app.py"]  
ENTRYPOINT ["python3"]
  • RUN: Execute commands and create new image layer.
  • CMD: Sets the command and its arguments to executed after container start. It’s can be override by docker run command line arguments
  • ENTRYPOINT: Configures the command to run when the container starts,

Tip

  1. Exec command: CMD ["executable", "param1", "param2"]
  2. CMD ["param1", "param2"] is use with ENTRYPOINT and provide extra parameters
  3. Shell format: CMD command param1 param2

Tip

docker run --entrypoint="path/to/custom/entrypoint" imagename

TKInter#

import tkinter as tk

# Tkinter Window
root_window = tk.Tk()

# Window Settings
root_window.title('Application Title')
root_window.geometry('300x100')
root_window.configure(background = '#353535')

# Text
tk.Label(root_window, text='Hello World', fg='White', bg='#353535').pack()

# Exit Button
tk.Button(root_window, text='Exit', width=10, command=root_window.destroy).pack()

# Main loop
root_window.mainloop()

Build And Usage#

Build app target#

docker build --target app \
-f Dockerfile \
-t my_gui_app:app ..
Tag description
–target app Build docker using the app stage
-f Dockerfile name to use
-t Tag image name
.. Set build context

Docker build context

A build’s context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context

Run#

docker run --entrypoint="/bin/sh" \
        -u=$(id -u $USER):$(id -g $USER) \
        -e DISPLAY=$DISPLAY \
        -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
        --rm \
        my_gui_app:app

override entrypoint#

  • Login in to sh terminal
docker run 
    --entrypoint="/bin/sh" \
    -u=$(id -u $USER):$(id -g $USER) \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
    --rm \
    -it \
    my_gui_app:app

Reference#